<template>
  <div class="wrapper">
    <JForm :form-config="dynamicValidateForm" @handleBoxEvent="handleBoxEvent" />
  </div>
</template>

<script>
import JForm from '@/components/JForm'
import { getDictListByType } from '@/api/dictionaries'

export default {
  name: 'DicUpdate',
  components: { JForm },
  props: {
    emitData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    const userInfo = [
      {
        name: 'name',
        label: '字典名称',
        type: 'string',
        required: true
      },
      {
        name: 'code',
        label: '字典编码',
        type: 'string',
        required: true,
        placeholder: '字典编码',
        value: ''
      },
      {
        name: 'dictLevel',
        label: '级别',
        type: 'string',
        required: true,
        placeholder: '级别',
        value: 0
      },
      {
        name: 'sortNum',
        label: '排序',
        type: 'string',
        required: false
      },
      // {
      //   name: 'dictTypeCode',
      //   label: '字典类型编码',
      //   type: 'string',
      //   required: false,
      //   placeholder: 'CITY_LEVEL',
      //   value: 'CITY_LEVEL'
      // },
      {
        name: 'localeId',
        label: '语言类型',
        type: 'switch',
        required: false,
        value: 'zh_cn',
        config: {
          activeText: '英文',
          inactiveText: '中文',
          activeValue: 'zh_cn',
          inactiveValue: 'en_us'
        }
      },
      {
        name: 'note',
        label: '备注',
        type: 'string',
        required: false
      }
    ]
    return {
      userInfo,
      formName: 'dynamicValidateForm',
      DicYN: [],
      DicYN01: []
    }
  },
  computed: {
    dynamicValidateForm() {
      const data = this.userInfo
      const result = data
      data.forEach(i => {
        if (this.emitData) {
          const { name } = i
          i.value = this.emitData[name]
        }
      })
      return result
    }
  },
  watch: {},
  created() {
    // 查询字典
    this.getDicYYZL()
  },
  mounted() {},
  methods: {
    getDicYYZL() {
      getDictListByType({ dictTypeCode: 'YYZL' }).then(res => {
        const { code, data /* message */ } = res
        if (code === 200) { this.DicYN = data }
        console.log('YYZL', res)
      })
    },
    handleBoxEvent(emitObj) {
      console.log(emitObj)
      this.$emit('handleBoxEvent', { target: emitObj })
    }
  }
}
</script>
<style lang="scss" scoped>
.wrapper{
   padding: 0px;
   margin: 0px;
}
</style>
